import { reqGetDetailInfoData } from '../../api/index';

const state = {
    detailInfo: [],
};

const actions = {
    async getDetailInfoData({ commit }, id) {
        const result = await reqGetDetailInfoData(id);
        if (result.code === 200) {
            commit('SAVE_DETAIL_INFO_DATA', result.data);
        }
    },
};

const mutations = {
    SAVE_DETAIL_INFO_DATA(state, detailInfo) {
        state.detailInfo = detailInfo;
    },
};

const getters = {
    categoryView(state) {
        return state.detailInfo.categoryView || {};
    },
    skuInfo(state) {
        return state.detailInfo.skuInfo || {};
    },
    spuSaleAttrList(state) {
        return state.detailInfo.spuSaleAttrList || {};
    },
};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters,
};
